// Effect.h: interface for the CEffect class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_EFFECT_H__6358680F_C482_4AF1_B1D3_5FF880DCB881__INCLUDED_)
#define AFX_EFFECT_H__6358680F_C482_4AF1_B1D3_5FF880DCB881__INCLUDED_

#if _MSC_VER > 1000 
#pragma once
#endif // _MSC_VER > 1000

class CEffect;
#include <vector>
#include <string>

struct EFFECTVERTEX
{
	FLOAT x, y, z;
	DWORD color;
	float tu, tv;
};

#define D3DFVF_EFFECTVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)

using namespace std;
#define MAX_EFFECTSLOT		100
#define MAX_EFFECTPLANE		150
#define MAX_EFFECTTEXTURE	32


typedef vector<std::string>					FUNCTION;
typedef vector<std::string>::iterator		FUNCITER;


typedef struct tag_Effect
{
	EFFECTVERTEX				vertex[4];
	LPDIRECT3DVERTEXBUFFER9		VertexBuffer;    	
	BOOL						Activate;
	LPDIRECT3DTEXTURE9			Texture;

//	D3DXVECTOR3					Vector;
	D3DXMATRIX					WorldMat;
	D3DXVECTOR3					WorldVec;
	D3DXVECTOR3					DynamicVec;
	float						Frame;
	float						Length;
	float						Dynamic;
	float						Speed;
	BOOL						IsCameraCoord;
	int							Code;
	BYTE*						DynamicPt1;
	BYTE*						DynamicPt2;	

	tag_Effect()		{
		ZeroMemory( vertex, sizeof(EFFECTVERTEX)*4 );
		VertexBuffer = NULL;
		Texture = NULL;
		Activate = FALSE;
		D3DXMatrixIdentity(&WorldMat);
		Frame = 0; Length=0;	Speed=0;	Dynamic=0;
		IsCameraCoord = FALSE;
		WorldVec.x=WorldVec.y=WorldVec.z=0;
		DynamicVec.x=DynamicVec.y=DynamicVec.z=0;
		DynamicPt1=NULL;
		DynamicPt2=NULL;
	}
	
} EFFECTPLANE;

typedef struct tag_EffectSlot
{
	EFFECTPLANE			Plane[MAX_EFFECTPLANE];
	BOOL				IsSwitchOn;
	int					PlaneCurPos;
	int					EffectNum;
	float				Frame;
	int					Dynamic;
	LPDIRECT3DTEXTURE9	Texture[16];
	void				(CEffect::*SetFunc) ( int );
	void				(CEffect::*RenderFunc) ( EFFECTPLANE* );

	tag_EffectSlot()	{
		ZeroMemory( Texture, sizeof(LPDIRECT3DTEXTURE9)*8 );
		IsSwitchOn = FALSE;
		PlaneCurPos = -1;
		EffectNum = -1;
		Frame = 0;
		Dynamic = -1;
	}

} EFFECTSLOT;

typedef struct tag_EffectTexture 
{
	LPDIRECT3DTEXTURE9		Texture;
	char					FileName[64];

	tag_EffectTexture()		{
		ZeroMemory( FileName, sizeof(char)*64 );
		Texture = NULL;
	}

} EFFECTTEXTURE;

typedef struct tag_sortslot
{
	EFFECTPLANE*		Plane;
	int					SlotOffset;
} SORTSLOT;

class CEffect 
{
public:
	CEffect();
	CEffect(LPDIRECT3DDEVICE9 pd3dDevice);
	virtual ~CEffect();
	
	D3DXMATRIX			m_ViewMat;

	EFFECTSLOT			m_Effect[MAX_EFFECTSLOT];
	int					m_CurrentPos;
//	int					m_StartPos;
	EFFECTTEXTURE		m_EffectTexture[MAX_EFFECTTEXTURE];
	

	LPDIRECT3DINDEXBUFFER9		m_PlaneIB;
	LPDIRECT3DDEVICE9			m_pd3dDevice;

	SORTSLOT					m_SortSlot[300];
	BOOL						m_IsSort;
	BOOL						m_Second, m_Third;

	FUNCTION					m_FunctionList;
	FUNCTION					m_TextureList;
	std::string					m_Directory;

	void		(CEffect::*InitFunc) ();
	void		SetFunction( int index );
	int			GetFunction();
	
	void		Rendering();
	void		InitEffect();
	void		RenderEffect( EFFECTPLANE *effect );
	int			GetEffectTextureID( char* filename );
	void		SetEffect();
	void		InitEffectSlot( EFFECTSLOT* slot );

	void		OnEffect_01();
	void		SetEffect_01( int offset );
	
/*	void		OnEffect_02(D3DXMATRIX worldmat, float size);
	void		SetEffect_02( int offset );
	void		RenderEffect_02( EFFECTPLANE *effect );
	void		OffEffect_02();
	void		OnEffect_02_1(D3DXMATRIX worldmat, float size);
	void		OnEffect_02_2(D3DXMATRIX worldmat, float size);
	void		OnEffect_02_3(D3DXMATRIX worldmat, float size);
	void		OnEffect_02_4(D3DXMATRIX worldmat, float size);

	void		OnEffect_03(D3DXMATRIX worldmat, D3DXMATRIX *LeftHand, D3DXMATRIX *RightHand, D3DXMATRIX *EnemyWorld, D3DXMATRIX worldrotate);
	void		SetEffect_03( int offset );
	void		RenderEffect_03( EFFECTPLANE *effect );
	void		OffEffect_03();
	void		OnEffect_03_1(D3DXMATRIX worldmat, D3DXMATRIX *LeftHand, D3DXMATRIX *RightHand, float size);
	void		OnEffect_03_2(D3DXMATRIX worldmat, D3DXMATRIX *LeftHand, D3DXMATRIX *RightHand, float size);
	void		OnEffect_03_3(D3DXMATRIX worldmat, D3DXMATRIX *Enemy,float size);
	void		OnEffect_03_4(D3DXMATRIX worldmat, D3DXMATRIX *LeftHand, D3DXMATRIX *RightHand, float size);
	void		OnEffect_03_5(D3DXVECTOR3 worldvec, float size);
	void		OnEffect_03_6(D3DXMATRIX worldmat, D3DXMATRIX worldrotate, float size);
	void		SetEffect_03_5( int offset );

	void		OnEffect_04(D3DXMATRIX EnemyWorld);
	void		OnEffect_04_1(D3DXMATRIX worldmat,float size);
	void		OnEffect_04_2(D3DXVECTOR3 vec, float size);
	void		RenderEffect_04( EFFECTPLANE *effect );
	void		SetEffect_04( int offset );
*/
};

#endif // !defined(AFX_EFFECT_H__6358680F_C482_4AF1_B1D3_5FF880DCB881__INCLUDED_)
